import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import px2rem from "postcss-plugin-px2rem";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

const px2remOptions = {
  rootValue: 16,
  unitPrecision: 5,
  mediaQuery: false,
  exclude: false,
};

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          prefix: "Icon",
        }),
      ],
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          enabledCollections: ["ep"],
        }),
      ],
    }),
  ],
  css: {
    postcss: {
      plugin: [px2rem(px2remOptions)],
    },
    preprocessorOptions: {
      scss: {
        api: "modern-compiler", // or 'modern'
      },
    },
  },
  server: {
    port: 5173,
    open: false,
    proxy: {
      "/api": {
        // target: "http:62.234.164.174:3000",
        target: "http:192.168.110.198:5000/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    },
  },
});
